<?php

namespace App\Http\Controllers\Api\v1;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\common;
use App\Logic\CommunityLogic;
/**
 * Undocumented class
 *  小区
 *  @zf
 */
class CommunityController extends Controller
{

    /**
     * Undocumented function
     *  小区列表
     * @return void
     */
    public function communityList(Request $request){
        try{
            if($request->method()!= 'GET')throw new \Exception('请求方式不正确');
            $paginate=$request->get('paginate');
            $fangList=CommunityLogic::communityList($paginate);
            return common::success(20000,$fangList,'加载成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
    }
    /**
     * 小区搜索
     */
    public function communitySearch(Request $request){
        try{
            if($request->method()!= 'GET')throw new \Exception('请求方式不正确');
            $name=$request->get('name');
            $address=$request->get('address');
            $paginate=$request->get('paginate');
            $fangList=CommunityLogic::communitySearch($name,$address,$paginate);
            return common::success(20000,$fangList,'加载成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
    }
     /**
     * Undocumented function
     *  小区详情
     * @return void
     */
    public function communityDetail(Request $request){
        try{
            if($request->method()!= 'GET')throw new \Exception('请求方式不正确');
            $id=$request->get('id');
            $request->validate([
                'id' =>'required',
            ]);
            $adminDetail=CommunityLogic::communityDetail($id);
            return common::success(20000,$adminDetail,'加载成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
     }
    /**
     * Undocumented function
     *  编辑小区信息
     * @return void
     */
    public function communitySave(Request $request){
        try{
            if($request->method()!= 'POST')throw new \Exception('请求方式不正确');
            $updata=$request->post();
            $save=CommunityLogic::communitySave($updata,$request);
            return common::success(20000,$save,'加载成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
     }
    /**
     * 小区删除
     */
    public function communityDel(Request $request){

        try{
            if($request->method()!= 'GET')throw new \Exception('请求方式不正确');
            $id=$request->get('id');
            $adminDel=CommunityLogic::communityDel($id);
            return common::success(20000,$adminDel,'查询成功');
        }catch(\Exception  $e){

            return common::fail(2001,'',$e->getMessage());
        }
    }
    /**
     * 小区redis
     */
    public function communityRedis(Request $request){

        try{
            if($request->method()!= 'GET')throw new \Exception('请求方式不正确');
            $adminDel=CommunityLogic::communityRedis();
            return common::success(20000,$adminDel,'查询成功');
        }catch(\Exception  $e){
            return common::fail(2001,'',$e->getMessage());
        }
    }
}
